package com.classroom.smart.controller;

import com.classroom.smart.pojo.Album;
import com.classroom.smart.result.CommonResult;
import com.classroom.smart.service.AlbumService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @Auther:YouGuoyun
 * @Title:leetcode
 * @Date:Create in 2023/2/25 10:23
 **/

@Controller
public class AlbumController {

    @Autowired
    private AlbumService albumService;


    @GetMapping("viewAlbum")
    @ResponseBody
    public CommonResult viewAlbum(
            @RequestParam(value = "current",required = false,defaultValue = "1")int current,
            @RequestParam(value = "query",required = false)String query
            ){
        List<Album> albums = albumService.viewAllAlbum(current,query);
        CommonResult commonResult = null;
        if (albums != null && albums.size() != 0){
            PageInfo<Album> pageInfo = new PageInfo<>(albums);
            HashMap<String,Object> hashMap = new HashMap<>();
            hashMap.put("pageInfo",pageInfo);
            hashMap.put("query",query);
            commonResult = new CommonResult(200,"查询成功",hashMap);
        }else {
            commonResult = new CommonResult(455,"查询失败");
        }
        return commonResult;
    }

}
